using SMGCore;

namespace Game {
	public sealed class ItemWorldPresenterPool : ManualSingleton<ItemWorldPresenterPool> {
		public BlockItemWorldPresenter BlockItemWorldPresenter;
		public CargoBoxItemPresenter   CargoBoxItemPresenter;
		public DebrisItemPresenter     DebrisItemPresenter;

		//TODO: pooling
		BlockItemWorldPresenter CreateBlockPresenter() {
			var inst = Instantiate(BlockItemWorldPresenter);
			inst.gameObject.SetActive(true);
			return inst;
		}

		public CargoBoxItemPresenter CreateCargoBoxItemPresenter() {
			var inst = Instantiate(CargoBoxItemPresenter);
			inst.gameObject.SetActive(true);
			return inst;
		}

		public DebrisItemPresenter CreateDebrisItemPresenter() {
			var inst = Instantiate(DebrisItemPresenter);
			inst.gameObject.SetActive(true);
			return inst;
		}

		public InventoryItemPresenter InventoryItemPresenterFactory(BaseInventoryItem item) {
			if ( item == null ) {
				return null;
			}
			if ( item is BlockItem ) {
				var p = CreateBlockPresenter();
				p.Setup((BlockItem)item);
				return p;
			}
			if ( item is DebrisItem) {
				var p = CreateDebrisItemPresenter();
				return p;
			}
			
			return CreateCargoBoxItemPresenter();
		}
	}

}
